package main

import (
	"errors"
	"fmt"
)

func main() {
	defer func() {
		fmt.Println("defer top")
		v := recover()
		if v != nil {
			fmt.Println(v)
		}
		fmt.Println("defer top finish")
	}()
	A()
	B()
	C()
	D()
}

func A() {
	fmt.Println("hello, i am a")
}

func B() {
	defer func() {
		fmt.Println("defer")
		v := recover()
		if v != nil {
			fmt.Println(v)
		}
		fmt.Println("defer finish")
	}()
	panic(errors.New("i am b, i am panic"))
	fmt.Println("hello, i am b")
}

func C() {
	fmt.Println("hello, i am c")
}

func D() {
	panic(errors.New("i am d, i am panic agaion"))
	fmt.Print("hello, i am d")
}
